#include "message.h"

Message::Message(const QString& messageId, MessageType messageType, const UserInfo& sender, const QString& chatSessionId, const QByteArray& content, const QString& fileName, const QString& fileSize)
    : m_messageId(messageId)
    , m_messageType(messageType)
    , m_sender(sender)
    , m_chatSessionId(chatSessionId)
    , m_content(content)
    , m_fileName(fileName)
    , m_fileSize(fileSize)
{} 

TextMessage::TextMessage(const QString& messageId, const UserInfo& sender, const QString& chatSessionId, const QByteArray& content)
    : Message(messageId, MessageType::TextType, sender, chatSessionId, content, "", "")
{}

ImageMessage::ImageMessage(const QString& messageId, const UserInfo& sender, const QString& chatSessionId, const QByteArray& content, const QString& fileName, const QString& fileSize)
    : Message(messageId, MessageType::ImageType, sender, chatSessionId, content, fileName, fileSize)
{}

FileMessage::FileMessage(const QString& messageId, const UserInfo& sender, const QString& chatSessionId, const QByteArray& content, const QString& fileName, const QString& fileSize)
    : Message(messageId, MessageType::FileType, sender, chatSessionId, content, fileName, fileSize)
{}

std::shared_ptr<Message> MessageFactory::makeMessage(MessageType messageType, const QString& chatSessionId, const UserInfo& sender, const QByteArray& content, const QString& fileName, const QString& fileSize)
{
    switch (messageType)
    {
        case MessageType::TextType:
            return std::make_shared<TextMessage>(messageId, sender, chatSessionId, content);
        case MessageType::ImageType:
            return std::make_shared<ImageMessage>(messageId, sender, chatSessionId, content, fileName, fileSize);
        case MessageType::FileType:
            return std::make_shared<FileMessage>(messageId, sender, chatSessionId, content, fileName, fileSize);
        default:
            return nullptr;
    }    
}

